#include "ReShade.fxh"

texture texColorBuffer : COLOR;
texture texDepthBuffer : DEPTH;

uniform float Fog_Intensity <
	ui_type = "drag";
	ui_min = 0; ui_max = 2;
	ui_label = "Fog Intensity";
	ui_tooltip = "Intensity of the fog.";
> = 1;

uniform float Fog_Additive <
	ui_type = "drag";
	ui_min = -2; ui_max = 2;
	ui_label = "Additive Fog Multiplier";
	ui_tooltip = "Makes fog Additive (1.0 for non additive)";
> = 1;

uniform float3 FogRGBBalance <
	ui_type = "drag";
	ui_min = 0; ui_max = 1;
	ui_label = "RGB Balance";
	ui_tooltip = "A per channel multiplier to the fog strength so you can give more boost to certain colors over others.";
> = float3(1.0, 1.0, 1.0);


sampler samplerDepth
{
	Texture = texDepthBuffer;
};

sampler samplerColor
{
	Texture = texColorBuffer;
};

void Fog(float4 pos : SV_Position, float2 texcoord : TEXCOORD0, out float4 color : SV_Target)
{
	float4 fogcolor = float4(FogRGBBalance.r, FogRGBBalance.g, FogRGBBalance.b,	Fog_Intensity);
	float depth = tex2D(samplerDepth, texcoord).r;
	depth = Fog_Intensity / (-99.0 * depth + 101.0);
	color = tex2D(samplerColor, texcoord);
	color = depth * fogcolor + (Fog_Additive - depth) * color;
}

technique Fog < enabled = true; >
{		
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = Fog;	
	}	
}